#!/bin/bash

echo "Which folder do you want to count?"
read path

cd $path

echo "------each flow:"
for i in $(seq 7)
do
    for j in $(seq 7)
    do
        if [ $i != $j ]; then
            echo "flow ${i}->${j}:  \c"
            loss_sum=$(awk -F' ' '{print $12$13}' s${i}h1Ts${j}h1 | grep '/' | awk -F'/' 'BEGIN{sum=0}{sum+=$1}END{print sum}')
            echo "  loss sum = ${loss_sum}\c"

            total_sum=$(awk -F' ' '{print $12$13}' s${i}h1Ts${j}h1 | grep '/' | awk -F'/' 'BEGIN{sum=0}{sum+=$2}END{print sum}')
            echo "  total sum = ${total_sum}\c"

            loss_rate=$(echo "scale=2; ${loss_sum}/${total_sum}" | bc)
            echo "  loss rate = ${loss_rate}"
        fi
    done
done 


echo "------all flow:"
loss_sum=$(awk -F' ' '{print $12$13}' s*T* | grep '/' | awk -F'/' 'BEGIN{sum=0}{sum+=$1}END{print sum}')
echo "loss sum = ${loss_sum}"

total_sum=$(awk -F' ' '{print $12$13}' s*T* | grep '/' | awk -F'/' 'BEGIN{sum=0}{sum+=$2}END{print sum}')
echo "total sum = ${total_sum}"

# bash不支持浮点除法
# loss_rate=$((${loss_sum}+${total_sum}))
loss_rate=$(echo "scale=2; ${loss_sum}/${total_sum}" | bc)
echo "loss rate = ${loss_rate}"




